package ipt.capitulo11;

class Buffer {
	private int n; // El buffer de 1 elemento
	private boolean leer = false;

	public synchronized void poner(int i) {
		try {
			while (leer)
				wait();
		} catch (InterruptedException e) {
			System.out.println(e.getMessage());
		}
		n = i;
		System.out.println("Se pone" + i);
		leer = true;
		notify();
	}

	public synchronized int quitar(int i) {
		try {
			while (!leer)
				wait();
		} catch (InterruptedException e) {
			System.out.println(e.getMessage());
		}

		n = i;
		System.out.println("Se quita" + n);
		leer = false;
		notify();
		return n;
	}
}